package com.jxmcloud.business.cut.json;

import lombok.extern.slf4j.Slf4j;
import com.jxmcloud.business.cut.service.logic.IConfigActionUtil;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.jxmcloud.business.cut.vo.json.ConfigItemVo;
import com.jxmcloud.business.cut.vo.json.ConfigActivityStartVo;
import com.jxmcloud.business.cut.vo.json.ConfigWheelInfoVo;
import com.jxmcloud.business.cut.vo.json.ConfigAwardVo;
import com.jxmcloud.business.cut.vo.json.ConfigStepVo;
import com.jxmcloud.business.cut.vo.json.ConfigStartVo;
import com.jxmcloud.business.cut.vo.json.ConfigProgressVo;
import com.jxmcloud.business.cut.vo.json.ConfigGlobalGlobalVo;
import com.jxmcloud.business.cut.vo.json.ConfigActivityTaskVo;
import com.jxmcloud.business.cut.vo.json.ConfigEventVo;
import com.jxmcloud.business.cut.vo.json.ConfigInviteAwardVo;
import com.jxmcloud.business.cut.vo.json.ConfigInviteProgressVo;


@Service
@Slf4j
public class DataConfigService implements ApplicationRunner {
    @Resource
	private IConfigActionUtil configActionUtil;

    @Resource
    private DataConfigItemLoader dataConfigItemLoader;

    @Resource
    private DataConfigActivityStartLoader dataConfigActivityStartLoader;

    @Resource
    private DataConfigWheelInfoLoader dataConfigWheelInfoLoader;

    @Resource
    private DataConfigAwardLoader dataConfigAwardLoader;

    @Resource
    private DataConfigStepLoader dataConfigStepLoader;

    @Resource
    private DataConfigStartLoader dataConfigStartLoader;

    @Resource
    private DataConfigProgressLoader dataConfigProgressLoader;

    @Resource
    private DataConfigGlobalGlobalLoader dataConfigGlobalGlobalLoader;

    @Resource
    private DataConfigActivityTaskLoader dataConfigActivityTaskLoader;

    @Resource
    private DataConfigEventLoader dataConfigEventLoader;

    @Resource
    private DataConfigInviteAwardLoader dataConfigInviteAwardLoader;

    @Resource
    private DataConfigInviteProgressLoader dataConfigInviteProgressLoader;


    @Override
    public void run(ApplicationArguments args) {
        do {
            boolean flag = false;
			flag = dataConfigItemLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigItemLoader");
				break;
			}
			flag = dataConfigActivityStartLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigActivityStartLoader");
				break;
			}
			flag = dataConfigWheelInfoLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigWheelInfoLoader");
				break;
			}
			flag = dataConfigAwardLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigAwardLoader");
				break;
			}
			flag = dataConfigStepLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigStepLoader");
				break;
			}
			flag = dataConfigStartLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigStartLoader");
				break;
			}
			flag = dataConfigProgressLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigProgressLoader");
				break;
			}
			flag = dataConfigGlobalGlobalLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigGlobalGlobalLoader");
				break;
			}
			flag = dataConfigActivityTaskLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigActivityTaskLoader");
				break;
			}
			flag = dataConfigEventLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigEventLoader");
				break;
			}
			flag = dataConfigInviteAwardLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigInviteAwardLoader");
				break;
			}
			flag = dataConfigInviteProgressLoader.loadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigInviteProgressLoader");
				break;
			}
			configActionUtil.initAllConfig();
		} while (false);
	}


    public void reloadConfig() {
        do {
            boolean flag = false;
			flag = dataConfigItemLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigItemLoader");
				break;
			}
			flag = dataConfigActivityStartLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigActivityStartLoader");
				break;
			}
			flag = dataConfigWheelInfoLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigWheelInfoLoader");
				break;
			}
			flag = dataConfigAwardLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigAwardLoader");
				break;
			}
			flag = dataConfigStepLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigStepLoader");
				break;
			}
			flag = dataConfigStartLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigStartLoader");
				break;
			}
			flag = dataConfigProgressLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigProgressLoader");
				break;
			}
			flag = dataConfigGlobalGlobalLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigGlobalGlobalLoader");
				break;
			}
			flag = dataConfigActivityTaskLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigActivityTaskLoader");
				break;
			}
			flag = dataConfigEventLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigEventLoader");
				break;
			}
			flag = dataConfigInviteAwardLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigInviteAwardLoader");
				break;
			}
			flag = dataConfigInviteProgressLoader.reloadFromDb();
			if (!flag) {
				log.error("配置加载失败: dataConfigInviteProgressLoader");
				break;
			}
		} while (false);
	}
	public ConfigItemVo getConfigItemConfig(Integer id) {return dataConfigItemLoader.getConfigById(id);}
	public ConfigItemVo getConfigItemConfig(Long id) {return dataConfigItemLoader.getConfigById(Math.toIntExact(id));}
	public ConfigActivityStartVo getConfigActivityStartConfig(Integer id) {return dataConfigActivityStartLoader.getConfigById(id);}
	public ConfigActivityStartVo getConfigActivityStartConfig(Long id) {return dataConfigActivityStartLoader.getConfigById(Math.toIntExact(id));}
	public ConfigWheelInfoVo getConfigWheelInfoConfig(Integer id) {return dataConfigWheelInfoLoader.getConfigById(id);}
	public ConfigWheelInfoVo getConfigWheelInfoConfig(Long id) {return dataConfigWheelInfoLoader.getConfigById(Math.toIntExact(id));}
	public ConfigAwardVo getConfigAwardConfig(Integer id) {return dataConfigAwardLoader.getConfigById(id);}
	public ConfigAwardVo getConfigAwardConfig(Long id) {return dataConfigAwardLoader.getConfigById(Math.toIntExact(id));}
	public ConfigStepVo getConfigStepConfig(Integer id) {return dataConfigStepLoader.getConfigById(id);}
	public ConfigStepVo getConfigStepConfig(Long id) {return dataConfigStepLoader.getConfigById(Math.toIntExact(id));}
	public ConfigStartVo getConfigStartConfig(Integer id) {return dataConfigStartLoader.getConfigById(id);}
	public ConfigStartVo getConfigStartConfig(Long id) {return dataConfigStartLoader.getConfigById(Math.toIntExact(id));}
	public ConfigProgressVo getConfigProgressConfig(Integer id) {return dataConfigProgressLoader.getConfigById(id);}
	public ConfigProgressVo getConfigProgressConfig(Long id) {return dataConfigProgressLoader.getConfigById(Math.toIntExact(id));}
	public ConfigGlobalGlobalVo getConfigGlobalGlobalConfig() {return dataConfigGlobalGlobalLoader.getConfigGlobalGlobal();}
	public ConfigActivityTaskVo getConfigActivityTaskConfig(Integer id) {return dataConfigActivityTaskLoader.getConfigById(id);}
	public ConfigActivityTaskVo getConfigActivityTaskConfig(Long id) {return dataConfigActivityTaskLoader.getConfigById(Math.toIntExact(id));}
	public ConfigEventVo getConfigEventConfig(Integer id) {return dataConfigEventLoader.getConfigById(id);}
	public ConfigEventVo getConfigEventConfig(Long id) {return dataConfigEventLoader.getConfigById(Math.toIntExact(id));}
	public ConfigInviteAwardVo getConfigInviteAwardConfig(Integer id) {return dataConfigInviteAwardLoader.getConfigById(id);}
	public ConfigInviteAwardVo getConfigInviteAwardConfig(Long id) {return dataConfigInviteAwardLoader.getConfigById(Math.toIntExact(id));}
	public ConfigInviteProgressVo getConfigInviteProgressConfig(Integer id) {return dataConfigInviteProgressLoader.getConfigById(id);}
	public ConfigInviteProgressVo getConfigInviteProgressConfig(Long id) {return dataConfigInviteProgressLoader.getConfigById(Math.toIntExact(id));}
}
